<?php
/**
 * @Author:      lyt
 * @DateTime:  2017-07-26 15:39:13
 * @Description: 套餐卡基本信息 产品信息
 */
class ServiceCardBasePack extends Eloquent
{
    protected $table = "service_card_base_pack";    
    
    /**
    * @Author:      zy
    * @DateTime:  2017-07-27 
    * @Description: 当前门店包含的套餐卡的产品,id的集合
    */
    public static function shopPackIds($shopid=null,$uid=null,$pack_id=null){
        $sql = "select DISTINCT (a.id) from service_card_detail_pack a 
                left join service_card_detail b on a.service_card_detail_id=b.id
                left join service_card_base_shop c on c.service_card_base_id = b.service_card_base_id
                where c.status=1 and b.status<>1";
        $array = [];
        if (!empty($shopid)){
            $sql .= " and c.shop_id = ? ";
            $array[] = $shopid;
        }
        
        if (!empty($uid)){
            $sql.=" AND b.user_id= ? ";
            $array[] = $uid;
        }
        if (!empty($pack_id)){
            $sql.=" AND pack_id= ? ";
            $array[] = $pack_id;
        }
        $ids_set = DB::select($sql , $array);
        $ids = "0"; //防止为空值报错

        if (!empty($ids_set)) {
            foreach ($ids_set as $v) {
                $ids .= ",{$v->id}";
            }
        }
        return $ids;
    }

    /**
    * @Author:      zy
    * @DateTime:  2017-07-27 
    * @Description: 当前门店包含的套餐卡的产品id的集合
    */
    public static function scdPackInfo($scd_id){
        $sql = "select * from service_card_detail_pack where service_card_detail_id=?";
        $info = DB::select($sql , [$scd_id]);
        return $info;
    }
    
    /**
    * @Author:      zy
    * @DateTime:  2017-07-27 
    * @Description: 返回【产品的id】的集合
    */
    public static function packIds($shopid,$uid){
        $sql = "select a.pack_id from service_card_detail_pack a 
                left join service_card_detail b on a.service_card_detail_id=b.id
                left join service_card_base_shop c on c.service_card_base_id = b.service_card_base_id
                where c.shop_id = ? and c.status=1 and b.status<>1 AND b.user_id= ? group by a.pack_id";
        $array = [$shopid,$uid];
        
        $ids_set = DB::select($sql , $array);
        $pack_ids = "0"; //防止为空值报错

        if (!empty($ids_set)) {
            foreach ($ids_set as $v) {
                $pack_ids .= ",{$v->pack_id}";
            }
        }
        return $pack_ids;
    }
}